package zhh.tangbao.user.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import zhh.tangbao.system.dto.BaseEntityUpdateDto;
import zhh.tangbao.system.entity.PagerEntity;
import zhh.tangbao.user.dto.UserDto;
import zhh.tangbao.user.entity.User;
import zhh.tangbao.user.vo.*;

import java.util.List;

/**
 * @author 粥灰灰
 * @created 2022/8/20
 * @version 1.0
 * @Description 关于用户的dao层操作
 */

@Repository
@Mapper
public interface UserDao extends BaseMapper<User> {

    /**
     * 获取用户除基本信息外，还有功能权限，角色信息等数据
     * @param userId
     * @return
     */
    UserVo getUserInfoById(String userId);


    /**
     * 获取用户登录验证用的信息
     * @param userAccount 用户账号
     * @return
     */
    UserLoginVo getUserLoginInfoByUserAccount(String userAccount);

    int insertUser(User user);

    int deleteUserById(Long id);

    int updateUser(@Param("user") User user);

    @Select("SELECT id FROM user WHERE data_status = 1")
    List<String> selectAllUserId();

    long count(@Param("dto") UserDto dto);

    List<UserPageVo> listUserPageVo(@Param("pager") PagerEntity<UserPageVo> pager, @Param("dto") UserDto dto);

    @Select("SELECT user.*, role.role_name FROM user JOIN role ON role.id = user.role_id WHERE user.id = #{id} AND user.data_status = 1")
    UserDetailInfoVo getUserDetailInfo(@Param("id") String id);

    int batchDeleteUserByIds(@Param("ids") List<String> ids, @Param("dto")BaseEntityUpdateDto dto);

    List<UserAccountAndNameVo> getUserAccountAndNameById(@Param("ids") List<String> ids);

    @Select("SELECT user_name FROM user WHERE id = #{id}")
    String getUserNameById(@Param("id") String responseUserId);
}
